package demo;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/HelloCookie")    //不再web.xml中配置，主解实现
public class HelloCookie extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws ServletException, IOException
    {
        // 设置响应内容类型
        response.setContentType("text/html");

        //request.getRequestDispatcher("https://baidu.com").forward(request,response);

        Cookie c=new Cookie("name","R_SESS");
        Cookie d=new Cookie("value","token-7955h:x66rzxb6zsk2ghhhtvjl5hdgn2q8x6q46gxk2gbtv7nmhdxm9lk7gw");

        response.addCookie(c);
        response.addCookie(d);


        //response.sendRedirect("https://baidu.com");

        String new_url = "http://hnsslxh.cn/hnwr/f";
        String html = "<script type='text/javascript'>location.href='"+new_url+"';</script>";
        response.getWriter().print(html);


    }

}
